<template>
  <div>
    <el-container>
      <el-header>&nbsp;人力资源管理系统</el-header>
      <el-container class="container">
        <el-aside width="300px">
          <Menu>

          </Menu>
        </el-aside>
        <el-container>
          <el-main
              ref="salaryStandFileReview"
              :model="salaryStandReviewFile"
              :rules="salaryStandReview"
          >
            <el-row>
              <el-col :span="22">
                <div class="grid-content bg-purple-dark">
                  <span>
                   薪酬标准复核
                  </span>
                </div>
              </el-col>
              <el-col :span="2">
                <div class="grid-content">
                  <!--                  TODO 写好后台 再写按钮方法-->
                  <el-button type="success" round @click="reviewSalary('salaryStandReviewFile')">复核通过</el-button>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬标准编号
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandReviewFile.salaryId" disabled placeholder="系统自动分配" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬标准登记
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandReviewFile.salaryName" placeholder="请填写标准名称" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬总额
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="formattedTotal" disabled placeholder="系统自动计算" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职位分类
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandReviewFile.cjobId" placeholder="请选择" v-on:change="getJobName" disabled style="width: 100%">
                    <el-option
                        v-for="item in salaryStandReview.JobClassification"
                        :label="item.cjobName"
                        :value="item.cjobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职位名称
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandReviewFile.njobId" placeholder="请选择" v-on:change="getJobTitle" disabled style="width: 100%">
                    <el-option
                        v-for="item in salaryStandReview.JobName"
                        :label="item.njobName"
                        :value="item.njobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职称
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandReviewFile.tjobId" placeholder="请选择" disabled style="width: 100%">
                    <el-option
                        v-for="item in salaryStandReview.JobTitle"
                        :label="item.tjobName"
                        :value="item.tjobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    制定人
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <!--                  TODO 写好登录来写-->
                  <el-input v-model="salaryStandReviewFile.maker" placeholder="请填写制定人" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    登记人
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandReviewFile.registrant" disabled />
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  登记时间
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandReviewFile.createTime" disabled placeholder="系统自动填写" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row style="height: 95px">
              <el-col :span="3">
                <div class="grid-content bg-purple" style="width: 220px; height: 95px; display:table-cell; vertical-align:middle">
                  <span>
                    复核意见
                  </span>
                </div>
              </el-col>
              <el-col :span="21">
                <div class="grid-content bg-purple-light" style="height: 95px">
                  <el-input
                      v-model="salaryStandReviewFile.reviewComments"
                      :rows="4"
                      type="textarea"
                      placeholder="请输入复核意见"
                  />
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    序号
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    薪酬项目名称
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    金额
                  </span>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    1
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    基本工资
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandReviewFile.basic" placeholder="请填写基本工资" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    2
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    交通补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandReviewFile.transportation" placeholder="请填写交通补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    3
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    午餐补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandReviewFile.lunch" placeholder="请填写午餐补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    4
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    通信补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandReviewFile.communication" placeholder="请填写通信补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    5
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    养老保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="formattedEndowment" placeholder="请填写养老保险" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    6
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    失业保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="formattedUnemployment" placeholder="请填写失业保险" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    7
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    医疗保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="formattedMedical" placeholder="请填写医疗保险" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    8
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    住房公积金
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="formattedProvidentFund" placeholder="请填写住房公积金" disabled clearable/>
                </div>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import{ defineComponent, ref }from 'vue'
import {
  Location,
  Document,
  Menu as IconMenu,
  Setting,
} from '@element-plus/icons-vue'
import Menu from "@/components/Menu";
export default defineComponent({
  name: "SalaryStandardReviewDetail",
  components: {
    Menu,
    Location,
    Document,
    Setting,
    IconMenu,
  },
  setup() {
    const activeNames = ref(['1'])
    const handleChange = (val) => {
      console.log(val)
    }

    return {
      activeNames,
      handleChange,
    }
  },
  data() {
    return {
      salaryStandReviewFile: {
        salaryId: '',
        salaryName: '',
        total: '',
        cjobId: '',
        njobId: '',
        tjobId: '',
        maker: '',
        registrant: '',
        createTime: '',
        basic: '',
        transportation: '',
        lunch: '',
        communication: '',
        endowment: '',
        unemployment: '',
        medical: '',
        providentFund: '',
        reviewComments: '',
      },
      salaryStandReview: {
        JobClassification: null,
        cjobName: null,
        cjobId: null,
        JobName: null,
        njobName: null,
        njobId: null,
        JobTitle: null,
        tjobName: null,
        tjobId: null,
      }
    }
  },
  computed: {
    formattedEndowment() {
      return this.salaryStandReviewFile.endowment ? parseFloat(this.salaryStandReviewFile.endowment).toFixed(2) : '';
    },
    formattedUnemployment() {
      return this.salaryStandReviewFile.unemployment ? parseFloat(this.salaryStandReviewFile.unemployment).toFixed(2) : '';
    },
    formattedMedical() {
      return this.salaryStandReviewFile.medical ? parseFloat(this.salaryStandReviewFile.medical).toFixed(2) : '';
    },
    formattedProvidentFund() {
      return this.salaryStandReviewFile.providentFund ? parseFloat(this.salaryStandReviewFile.providentFund).toFixed(2) : '';
    },
    formattedTotal() {
      return this.salaryStandReviewFile.total ? parseFloat(this.salaryStandReviewFile.total).toFixed(2) : '';
    },
  },
  methods: {
    reviewSalary(formName) {
      this.axios.post('/salary/reviewSalary',this.salaryStandReviewFile,{
        //TODO 权限控制，先不写
        //TODO 提示框
        //TODO 审核人信息还没加
      }).then(res =>{
        this.$router.push("/SalaryStandardReview")
      })
    },

    getJobClassification() {
      this.axios.get('/selectJobClassification').then(res =>{
        const _this = this
        _this.salaryStandReview.JobClassification = res.data.data
      }).then(res =>{
        this.getJobName()
      })
    },
    getJobName() {
      this.axios.get('/selectJobName/'+ this.salaryStandReviewFile.cjobId).then(res =>{
      const _this = this
      _this.salaryStandReview.JobName = res.data.data
      }).then(res =>{
        this.getJobTitle()
      })
    },
    getJobTitle() {
      this.axios.get('/selectJobTitle/'+ this.salaryStandReviewFile.njobId).then(res =>{
        const _this = this
        _this.salaryStandReview.JobTitle = res.data.data
      })
    },
    /*updateSalary() {
      this.salaryStandReviewFile.endowment = Number(this.salaryStandReviewFile.basic*0.08)
      this.salaryStandReviewFile.medical = Number((this.salaryStandReviewFile.basic*0.02) + 3)
      this.salaryStandReviewFile.unemployment = Number(this.salaryStandReviewFile.basic*0.005)
      this.salaryStandReviewFile.providentFund = Number(this.salaryStandReviewFile.basic*0.08)
      this.salaryStandReviewFile.total = Number(this.salaryStandReviewFile.basic) +
          Number(this.salaryStandReviewFile.transportation) +
          Number(this.salaryStandReviewFile.lunch) +
          Number(this.salaryStandReviewFile.communication) +
          Number(this.salaryStandReviewFile.endowment) +
          Number(this.salaryStandReviewFile.medical) +
          Number(this.salaryStandReviewFile.unemployment) +
          Number(this.salaryStandReviewFile.providentFund)
    },*/
    updateSalary() {
      this.salaryStandReviewFile.endowment = Number((this.salaryStandReviewFile.basic * 0.08)).toFixed(2);
      this.salaryStandReviewFile.medical = Number((this.salaryStandReviewFile.basic * 0.02) + 3).toFixed(2);
      this.salaryStandReviewFile.unemployment = Number((this.salaryStandReviewFile.basic * 0.005)).toFixed(2);
      this.salaryStandReviewFile.providentFund = Number((this.salaryStandReviewFile.basic * 0.08)).toFixed(2);
      this.salaryStandReviewFile.total = (
          Number(this.salaryStandReviewFile.basic) +
          Number(this.salaryStandReviewFile.transportation) +
          Number(this.salaryStandReviewFile.lunch) +
          Number(this.salaryStandReviewFile.communication) +
          Number(this.salaryStandReviewFile.endowment) +
          Number(this.salaryStandReviewFile.medical) +
          Number(this.salaryStandReviewFile.unemployment) +
          Number(this.salaryStandReviewFile.providentFund)
      ).toFixed(2);
    },
  },
  created() {
    const salaryId = this.$route.params.salaryId
    const _this = this
    if(salaryId) {
      this.axios.get('/salary/ReviewDetail/' + salaryId).then(res =>{
        const salaryStand = res.data.data
        _this.salaryStandReviewFile.salaryId = salaryStand.salaryId
        _this.salaryStandReviewFile.salaryName = salaryStand.salaryName
        _this.salaryStandReviewFile.total = salaryStand.total
        _this.salaryStandReviewFile.cjobId = salaryStand.cjobId
        _this.salaryStandReviewFile.njobId = salaryStand.njobId
        _this.salaryStandReviewFile.tjobId = salaryStand.tjobId
        _this.salaryStandReviewFile.maker = salaryStand.maker
        _this.salaryStandReviewFile.registrant = salaryStand.registrant
        _this.salaryStandReviewFile.createTime = salaryStand.createTime
        _this.salaryStandReviewFile.basic = salaryStand.basic
        _this.salaryStandReviewFile.transportation = salaryStand.transportation
        _this.salaryStandReviewFile.lunch = salaryStand.lunch
        _this.salaryStandReviewFile.communication = salaryStand.communication
        _this.salaryStandReviewFile.endowment = salaryStand.endowment
        _this.salaryStandReviewFile.unemployment = salaryStand.unemployment
        _this.salaryStandReviewFile.medical = salaryStand.medical
        _this.salaryStandReviewFile.providentFund = salaryStand.providentFund
      }).then(res =>{
        this.getJobClassification()
      })
    }
  }

})
</script>

<style scoped>
.el-header{
  background-color: #409EFF;
  color: #e9eef3;
  text-align: left;
  line-height: 60px;
  font-size: 30px;
}
.el-aside {
  background-color: #d3dce6;
  color: var(--el-text-color-primary);
  text-align: center;
  /*line-height: 860px;*/
}

.el-main {
  background-color: #e9eef3;
  color: var(--el-text-color-primary);
  text-align: center;
  line-height: 30px;
}

body > .el-container {
  margin-bottom: 400px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-row {
  margin-bottom: 20px;
}

.el-row :last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.high-row{
  min-height: 200px;
}

.container{
  min-height: 860px;
}

.line {
  width: 70%;
}

.line div {
  width: 100%;
  height: 0;
  border-top: 1px solid var(--el-border-color-base);
}

</style>